package cn.yunhe.util;

import cn.yunhe.model.*;

import java.util.Iterator;
import java.util.List;

public class ModelDisplayUtil {


    public  static void listHouse(List<House> houseList){
        for (House house:houseList){
            singleHouse(house);
        }
    }

    public  static void singleHouse(House house){
        System.out.print(house.getHid()+"\t");
        System.out.print(house.getHtitle()+"\t");
        System.out.print(house.getHprice()+"\t");
        System.out.print(house.getHfloorage()+"\t");
        System.out.print(house.getHpubdate()+"\t");
        System.out.print(house.getHcontact()+"\t");
        System.out.print(house.getHdesc()+"\t");
        System.out.print(house.getHflag()+"\t");
        if (house.getMember()!=null&&house.getMember().getMname()!=null)
            System.out.print(house.getMember().getMname()+house.getMember().getMid()+"\t");
        if (house.getType()!=null&&house.getType().getTname()!=null)
            System.out.print(house.getType().getTname()+house.getType().getTid()+"\t");
        if (house.getStreet()!=null&&house.getStreet().getSname()!=null)
            System.out.print(house.getStreet().getSname()+house.getStreet().getSid()+"\t");
        if (house.getStreet()!=null&&house.getStreet().getDistrict()!=null&&house.getStreet().getDistrict().getDname()!=null)
            System.out.print(house.getStreet().getDistrict().getDname()+house.getStreet().getDistrict().getDid()+"\t");
        System.out.println();
    }


    public static void listDistrict(List<District> districtList){
        for (District district:districtList){
            singleDistrict(district);
        }
    }

    public  static void singleDistrict(District district){
        System.out.print(district.getDid()+"\t");
        System.out.print(district.getDname()+"\t");
        System.out.println("\n====================");
        Iterator iterator= district.getStreetSet().iterator();
        while (iterator.hasNext()){
            Street street= (Street) iterator.next();
            System.out.print(street.getSid()+"\t");
            System.out.print(street.getSname()+"\t");
        }
        System.out.println("\n====================");
        System.out.println();
    }

    public static void listMember(List<Member> memberList){
        for (Member member:memberList){
            singleMember(member);
        }
    }

    public static void singleMember(Member member){
        System.out.print(member.getMid()+"\t");
        System.out.print(member.getMaccount()+"\t");
        System.out.print(member.getMpwd()+"\t");
        System.out.print(member.getMname()+"\t");
        System.out.print(member.getMstate()+"\t");
        System.out.print(member.getMflag()+"\t");
        System.out.println(member.getHouseSet()+"\t");
        System.out.println("\n====================");
        Iterator<House>iterator=member.getHouseSet().iterator();
        while (iterator.hasNext()){
            House house=iterator.next();
            ModelDisplayUtil.singleHouse(house);
        }
        System.out.println("\n====================");
        System.out.println();
    }
    
    public static void listStreet(List<Street> streetList){
        for (Street street:streetList){
            singleStreet(street);
        }
    }

    public static void singleStreet(Street street){
        System.out.print(street.getSid()+"\t");
        System.out.print(street.getSname()+"\t");
        System.out.print(street.getDistrict().getDid()+"\t");
        System.out.print(street.getDistrict().getDname()+"\t");
        System.out.println("\n====================");
        Iterator<House>iterator=street.getHouseSet().iterator();
        while (iterator.hasNext()){
            House house=iterator.next();
            ModelDisplayUtil.singleHouse(house);
        }
        System.out.println("\n====================");
        System.out.println();
    }
    
    public static void listType(List<Type> typeList){
        for (Type type:typeList){
            singleType(type);
        }
    }

    public static void singleType(Type type){
        System.out.print(type.getTid()+"\t");
        System.out.print(type.getTname()+"\t");
        System.out.println("\n====================");
        Iterator<House>iterator=type.getHouseSet().iterator();
        while (iterator.hasNext()){
            House house=iterator.next();
            ModelDisplayUtil.singleHouse(house);
        }
        System.out.println("\n====================");
        System.out.println();
    }
    
    
    
}
